/*
 *  $Id: UseAbility.cs 1217 2010-11-27 10:48:54Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2010 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using Nereal.Extensions;
using Nereal.Serialization;

namespace Ragima.Events {
    /// <summary>
    /// Событие использования способности. Содержит параметры цели и способность.
    /// </summary>
    [TypeId("useability"), ConstructorParameters("_abilityNumber", "Args")]
    public class UseAbility : TargetEvent {
        [Serialize, XmlName("ability"), DefaultValue(-1)]
        private int _abilityNumber;

        public UseAbility(AbilityCard ability, TargetArgs args) : this(args.Caster.GetAbilities().IndexOf(ability), args) {
        }
        public UseAbility(int abilityNumber, TargetArgs args) : base(args) {
            _abilityNumber = abilityNumber;
        }

        protected override void ExecuteInner(Game scene) {
            if (Args == null)
                return;
            var ability = Args.Caster.GetAbilities().GetOrDefault(_abilityNumber);
            if (ability != null)
                Args.Player.DoUse(ability, Args);
        }
    }
}
